/**
 * $Revision: 1.0 $
 * $Author: Eric Yang $
 * $Date: Jan 15, 2010 12:01:56 AM $
 *
 * Author: Eric Yang
 * Date  : Jan 15, 2010 12:01:56 AM
 *
 */
package com.gooex.web.action.manage.product;

import org.c4j.string.StringTools;

import com.gooex.domain.base.Product;
import com.gooex.service.base.IProductManager;
import com.gooex.web.action.BaseManageableAction;


/**
 * @author Eric Yang
 * @version 1.0
 */
public class ManageProductOperateAction extends BaseManageableAction {

	private IProductManager productManager;

	private Product product;

	private String target;

	private String id;

	public String save() throws Exception {
		if (product == null) {
			return INPUT;
		}
		if (StringTools.isNotBlankOrNull(product.getId())) {
			// CHECK WHETHER CAN EDIT THE PRODUCT
		}
		productManager.saveProduct(product);
		id = product.getId();
		if (target != null && ("product".equals(target) || "order".equals(target))) {
			return target;
		}

		return SUCCESS;
	}

	public String remove() throws Exception {
		Product product = productManager.getProduct(id);
		if (product != null && getCurrentUser().equals(product.getUser()))
			productManager.removeProduct(product);
		return SUCCESS;
	}

	public String authorite() throws Exception {
		Product product = productManager.getProduct(id);
		if (product != null && isSystemUser()) {
			product.setRaw(false);
			productManager.saveProduct(product);
		}
		return SUCCESS;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	public void setProductManager(IProductManager productManager) {
		this.productManager = productManager;
	}

	public String getTarget() {
		return target;
	}

	public void setTarget(String target) {
		this.target = target;
	}

	public String getId() {
		return id;
	}
}
